﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Text;

namespace ALinq.BBS.Common.Config
{
    public class UploadElement : ConfigurationElement
    {
        [ConfigurationProperty("groupID")]
        public int GroupID
        {
            get { return (int) base["groupID"]; }
            set { base["groupID"] = value; }
        }

        [ConfigurationProperty("types", DefaultValue = ".txt .jpg .jpeg .gif .bmp .zip .rar")]
        public string FileTypes
        {
            get { return (string) base["types"]; }
            set { base["types"] = value; }
        }
    }

    public class UploadElementCollection : ConfigurationElementCollection<UploadElement>
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new UploadElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((UploadElement)element).GroupID;
        }

        public new UploadElement this[object key]
        {
            get
            {
                UploadElement item = (UploadElement) BaseGet(key);
                if(item == null)
                {
                    item = new UploadElement();
                    item.GroupID = (int) key;
                    BaseAdd(item);
                }
                return item;
            }
        }

    }
}